﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AdvanceLib.Core
{
    public class EventManager : Singleton<EventManager>
    {
        #region Constructors
        public EventManager()
        {
            this.Events = new Dictionary<string, List<EventHandler>>();
        }
        #endregion

        #region Properties
        public Dictionary<string, List<EventHandler>> Events { get; set; }
        #endregion

        #region Methods
        public void AddEvent(string name)
        {
            if (!this.Events.ContainsKey(name))
                this.Events.Add(name, new List<EventHandler>());
        }
        public void InvokeEvent(string name, EventArgs e)
        {
            if (this.Events.ContainsKey(name))
            {
                foreach (EventHandler handler in this.Events[name])
                    handler.Invoke(this, e);
            }
        }
        public void AddHandler(string eventName, EventHandler handler)
        {
            if (this.Events.ContainsKey(eventName))
                this.Events[eventName].Add(handler);
        }
        #endregion
    }
}
